package cn.com.connected.vo.wechat;

import lombok.Data;

import java.io.Serializable;

/**
 * 微信返回签名的签名数据
 */
@Data
public class JsApiTicket implements Serializable {

	/**
	 * 错误码
	 */
	private String errcode;
	/**
	 * 错误信息
	 */
	private String errmsg;
	/**
	 * 临时票据
	 */
	private String ticket;
	/**
	 * 过期时间
	 */
	private int expires_in;
	/**
	 * 创建时间
	 */
	private long create_time;

	public JsApiTicket(){
		this.create_time = System.currentTimeMillis();
	}

	public boolean isVail(){
		return isVail(600);
	}

	public boolean isVail(int beforehand){
        long passTime = (System.currentTimeMillis()-create_time)/1000;
        if(passTime>=(expires_in-beforehand)){
            return false;
        }else{
            return true;
        }
    }
}
